﻿// ***********************************************************************
// Provided for Informational Purposes Only
//
// Apache 2.0 License
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
//
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY 
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR 
// PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
//
// See the Apache Version 2.0 License for specific language governing
// permissions and limitations under the License.
// ***********************************************************************
// Assembly  : ContractMeow.Api.WinRT
// File      : ClientsConfiguration.cs
//
// ***********************************************************************
using ContractMeow.WinRT.Extensions;
using System;

namespace ContractMeow.Api
{
	public class ClientConfiguration : IClientConfiguration
	{
		public const Double DefaultTimeoutSeconds = 100;
		public const String ProductionUri = "https://www.yammer.com";
		public const String ProductionUploadUri = "https://files.yammer.com";

		public String UserAgent { get; protected set; }

		public Uri BaseUri { get; set; }
		public Uri BaseUploadUri { get; set; }

		public String ClientSecret
		{
			get { return _clientSecret; }
		}

		private readonly String _clientSecret;

		public String ClientId
		{
			get { return _clientId; }
		}

		private readonly String _clientId;

		public TimeSpan Timeout
		{
			get { return _timeout; }
		}

		private readonly TimeSpan _timeout;

		public ClientConfiguration(
			String clientId,
			String clientSecret,
			String baseUri = null,
			TimeSpan? timeout = null,
			String baseUploadUri = null)
		{
			if (String.IsNullOrWhiteSpace(clientId))
				throw new ArgumentException("Invalid clientId specified.");
			if (String.IsNullOrWhiteSpace(clientSecret))
				throw new ArgumentException("Invalid clientSecret specified.");
			if (!String.IsNullOrWhiteSpace(baseUri) && !baseUri.IsUri())
				throw new ArgumentException("Invalid baseUri specified.");
			if (timeout != null && timeout.Value.Seconds < 10)
				throw new ArgumentException("Invalid timeout specified.");

			this._clientId = clientId;
			this._clientSecret = clientSecret;
			this.BaseUri = String.IsNullOrWhiteSpace(baseUri)
							   ? new Uri(ProductionUri)
							   : new Uri(baseUri);
			this.BaseUploadUri = String.IsNullOrWhiteSpace(baseUploadUri)
									 ? new Uri(ProductionUploadUri)
									 : new Uri(baseUploadUri);
			this._timeout = timeout ?? TimeSpan.FromSeconds(DefaultTimeoutSeconds);

		}
	}
}
